axios.defaults.baseURL=`http://api-breakingnews-web.itheima.net`

axios.interceptors.request.use(config => {
// Do something before request is sent
if (config.url.indexOf('/my') !==-1){ config.headers.Authorization = localStorage.getItem('token')
console.log(config.url.indexOf('/my'));
}
// if (config.url.includes('/my')) {
//     config.headers.Authorization = localStorage.getItem('token')
// }
return config;
},error => {
// Do something with request error
return Promise.reject(error);
});

// 响应拦截器
axios.interceptors.response.use(response => {
// Do something before response is sent
if (response.data.status=== 1&&response.data.message==='身份验证失败！') {
    location.href='/login.html'
}
return response;
},error => {
// Do something with response error
return Promise.reject(error);
});